package com.aircms.controller.admin;

import com.aircms.common.ServerResponse;
import com.aircms.controller.BaseAdminController;
import com.aircms.pojo.vo.RolePermissionVo;
import com.aircms.service.IRolePermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author air
 * @create 2018-07-05 上午10:59
 */
@RestController
@RequestMapping(value = "api/admin/auth/rolePermission")
public class RolePermissionAdminController extends BaseAdminController {

    @Autowired
    private IRolePermissionService iRolePermissionService;

    /**
     * Display a listing of the resource.
     *
     * @return
     */
    @GetMapping(value = (""))
    public ServerResponse index() {

        return ServerResponse.response();
    }


    /**
     * Store a newly created resource in storage.
     *
     * @return
     */
    @PostMapping(value = "")
    public ServerResponse store(@RequestBody RolePermissionVo rolePermissionVo) throws Exception{
        try{
            return  iRolePermissionService.store(rolePermissionVo);
        }catch (Exception e){
            this.errorLog(this.getClass(),e);
            throw new Exception("添加失败");
        }
    }





    /**
     * Show the form for editing the specified resource.
     *
     * @param id
     * @return
     */
    @GetMapping(value = "{id}/edit")
    public ServerResponse edit(@PathVariable Integer id) {

        return ServerResponse.response();
    }


    /**
     * Update the specified resource in storage.
     *
     * @return
     */
    @RequestMapping(value = "{id}", method = {RequestMethod.PUT, RequestMethod.PATCH})
    public ServerResponse update(@PathVariable Integer id) {

        return ServerResponse.response();
    }


    /**
     * Remove the specified resource from storage.
     *
     * @param id
     * @return
     */
    @DeleteMapping(value = "{id}")
    public ServerResponse destroy(@PathVariable Integer id) throws Exception{
        try{
            return iRolePermissionService.destroy(id);
        }catch (Exception e){
            this.errorLog(this.getClass(),e);
            throw new Exception("删除失败");
        }
    }


    @GetMapping(value = "getPermissionByRoleId")
    public ServerResponse getPermissionByRoleId(Integer roleId){
        return ServerResponse.response();
    }


}
